package com.qf.flash.mvp.presenter;

import com.qf.dblib.dao.impl.UserMgr;
import com.qf.flash.http.HttpManager;
import com.qf.flash.model.MyLaunchBean;
import com.qf.flash.mvp.contract.MyLanchedActContract;
import com.qf.flash.utils.LogUtil;
import com.qf.flashlib.base.BasePresenter;
import com.qf.flashlib.base.BaseResponse;
import com.qf.flashlib.base.BaseSubscriber;
import com.qf.flashlib.exception.ApiException;
import com.qf.flashlib.util.RxUtils;

import java.util.List;

public class MyLanchedActPresenter extends BasePresenter<MyLanchedActContract.View> implements MyLanchedActContract.Presenter {
    private String uid = UserMgr.getInstance().getLoginUser().getUid();

    @Override
    public void getMyLanchedAct(int num, int size) {

        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .MY_START_LIST(uid, num, size)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<List<MyLaunchBean>>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<List<MyLaunchBean>> response) {
                        mRootView.setLaunchBean(response.getData(),response.getTotalPage());

                    }

                    @Override
                    public void onError(ApiException e) {
                        super.onError(e);
                    }
                })
        );
    }

    @Override
    public void getMyJoinGame(int num, int size) {
        addSubscription(HttpManager.getInstance().getGsonHttpApi()
                .MY_JOIN_GAME(uid, num, size)
                .compose(RxUtils.handleBaseResult())
                .compose(RxUtils.io_main())
                .subscribeWith(new BaseSubscriber<BaseResponse<List<MyLaunchBean>>>(mRootView) {
                    @Override
                    public void onSuccess(BaseResponse<List<MyLaunchBean>> listBaseResponse) {
                        mRootView.setMyJoinedGame(listBaseResponse.getData(),listBaseResponse.getTotalPage());
                    }
                }));

    }

}
